<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
</html>
<script>
    // 通过#修饰私有成员
        class Person{
            // name = "张三"    // 设置属性方式2
            #weight = "50kg";
            constructor(name,age){
                // this.name = "张三";  // 设置属性方式1
                this.name = name;
                this.age = age;
            }
            gitWeight(){
                // 公有方法调取私有属性
                return this.#weight;
            }
            #fn(){
                console.log("私有方法");
            }
        }
        let zhangsan = new Person("张三");
        console.log(zhangsan);
        console.log(zhangsan.gitWeight());


        class Persons{
            age = 20;   // 方式2
            constructor(){
                this.name = "abs";    // 方式1
                this.myheight = "178cm";
            }
            get height(){
                console.log("get执行");
                return this.myheight;
            }
            set height(newheight){
                console.log("新设置的值是",newvalue);
            }
        }
        let lisi = new Persons();
        console.log(lisi);










</script>